<?php
namespace app\admin\controller;
class Message extends Common
{
    public function index(){
        if(request()->isPost()) {
            $key=input('post.key');
            $page =input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):config('pageSize');
            $list = db('messages')->alias('u')
                ->join(config('database.prefix').'users ul','u.user_id = ul.id','left')
                ->join(config('database.prefix').'users ol','u.be_user_id = ol.id','left')
                ->field('u.*,ul.username as username,ol.username as be_username')
                ->where('u.content', 'like', "%" . $key . "%")
                ->where('u.status','neq',0)
                ->where('ul.status','eq',1)
                ->where('ol.status','eq',1)
                ->order('u.id desc')
                ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                ->toArray();
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
        }
        return $this->fetch();
    }
    //删除留言
    public function del(){
        // $map['id']=input('id');
        db('messages')->where('id','eq',input('id'))->update(array('status'=>0));
        return $result = ['code'=>1,'msg'=>'删除成功!'];
    }
    public function delall(){
        $map[] =array('id','IN',input('param.ids/a'));
        db('messages')->where($map)->update(array('status'=>0));
        $result['msg'] = '删除成功！';
        $result['code'] = 1;
        $result['url'] = url('index');
        return $result;
    }
}